using Game.Framework.FState;
using Game.Framework.UI;
using Game.Framework.Utils;
using UnityEngine;

namespace Game.Applcation
{
    public class App : MonoBehaviour
    {
        public static App Instance;
        public StateMachine<StateMainBase> StateMachine;
        public Camera MainCamera;
        
        public static void Init()
        {
            var app = new GameObject("App");
            Instance = app.AddComponent<App>();
            Instance.Load();
        }

        private void Load()
        {
            UIManager.Instance.Init();
            MainCamera = GameObject.Find("Camera").GetComponent<Camera>();
            
            StateMachine = new StateMachine<StateMainBase>();
            ChangeState<StateLaunch>(null);
        }
        
        public void ChangeState<T>(StateData param) where T : StateMainBase, new()
        {
            StateMachine.SetState<T>(param);
        }

        void Update()
        {
            StateMachine.Update();
        }

        private void FixedUpdate()
        {
            StateMachine.FixedUpdate(Time.deltaTime);
        }
    }
}


